package controllers;

import is.ru.honn.rupin.data.BoardDataGateway;
import is.ru.honn.rupin.data.FollowerDataGateway;
import is.ru.honn.rupin.data.PinDataGateway;
import is.ru.honn.rupin.data.UserDataGateway;
import is.ru.honn.rupin.domain.Board;
import is.ru.honn.rupin.domain.Pin;
import is.ru.honn.rupin.domain.UserAuthentication;
import is.ru.honn.rupin.service.FollowerService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import play.*;
import play.mvc.*;
import views.html.*;
import views.html.session.*;

import java.util.List;

/**
 * A class containing only the index function
 * @author Einar
 * @author Jón Atli
 * @version 0.9
 */
public class Application extends RuPinController {

    /**
     * Function renders a list of pins gathered from followerService
     * @return the index view
     */
  public static Result index() {
        if(Session.isValidated()){
            List<Pin> boards = followerService.getFolloweePins(session().get("username"));
            return ok(index.render(boards, session().get("Name")));
        }
        else {
            return redirect(routes.Session.login());
        }
  }
}